<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" placeholder="请输入您的存款本金" class="price" />
    <input type="text" placeholder="请输入存款年份" class="x1" />
    <button>点我</button>
    <input type="text" placeholder="您的月利息在这里嗷" class="m1" />
  </body>
</html>
<script>
  var p1 = document.querySelector(".price");
  var btn = document.querySelector("button");
  var money = document.querySelector(".m1");
  var year = document.querySelector(".x1");
  btn.onclick = function () {
    if (p1.value.trim() == "") return alert("请输入内容");
    if (year.value.trim() == "") return alert("请输入内容");
    if (isNaN(p1.value)) return alert("请输入数字");
    if (isNaN(year.value)) return alert("请输入数字");
    if (p1.value < 0 || year.value < 0)
      return alert("请输入正确年份或者存款金额");
    switch (year.value) {
      case "1":
        money.value = p1.value * 1 * (0.0063 * 12) * (year.value * 1);
        break;
      case "2":
        money.value = p1.value * 1 * (0.0066 * 12) * (year.value * 1);
        break;
      case "3":
        money.value = p1.value * 1 * (0.0069 * 12) * (year.value * 1);
        break;
      case "5":
        money.value = p1.value * 1 * (0.0075 * 12) * (year.value * 1);
        break;
      case "8":
        money.value = p1.value * 1 * (0.0084 * 12) * (year.value * 1);
        break;
      default:
        alert("请输入有效存款年份");
        break;
    }
    // if (year.value == "1") {
    //   money.value = p1.value * 1 * (0.0063 * 12) * (year.value * 1);
    // } else if (year.value == "2") {
    //   money.value = p1.value * 1 * (0.0066 * 12) * (year.value * 1);
    // } else if (year.value == "3") {
    //   money.value = p1.value * 1 * (0.0069 * 12) * (year.value * 1);
    // } else if (year.value == "5") {
    //   money.value = p1.value * 1 * (0.0075 * 12) * (year.value * 1);
    // } else if (year.value == "8") {
    //   money.value = p1.value * 1 * (0.0084 * 12) * (year.value * 1);
    // } else {
    //   alert("年份不适用");
    // }
  };
</script>
